import request from './Request'

/**
 * 登录
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const login = (obj) => {
  return request({
    method: 'post',
    url: '/account/login',
    data: obj,
    showLoading: false
  }).then(res => {
    return res.data
  })
}
/**
 * 获取验证码
 * @returns {Promise<AxiosResponse<any>>}
 */
const captcha = () => {
  return request({
    method: 'get',
    url: '/account/captcha',
    showLoading: true
  }).then(res => {
    return res.data
  })
}

/**
 * 注册
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const register = (obj) => {
  return request({
    method: 'post',
    url: '/account/register',
    data: obj,
    showLoading: true
  }).then(res => {
    return res.data
  })
}
/**
 * 重置密码
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const resetPassword = (obj) => {
  return request({
    method: 'post',
    url: '/account/resetPassword',
    data: obj,
    showLoading: true
  }).then(res => {
    return res.data
  })
}
/**
 * 获取联系人
 * @returns {Promise<AxiosResponse<any>>}
 */
const getContactList = (userId) => {
  return request({
    method: 'post',
    url: '/account/contactList',
    data:{
      userId:userId
    },
    showLoading: false
  }).then(res => {
    return res.data
  })
}

const getUser = (arg) => {
  return request({
    method: 'post',
    url: '/account/getUserInfo',
    data: {
      id: arg
    },
    showLoading: false
  }).then(res => {
    return res.data
  })
}

const uploadAvatar = (arg) => {
  return request({
    method: 'post',
    url: '/file/avatar',
    data: arg,
    uploadFile: true,
    showLoading: false
  }).then(res => {
    return res.data
  })
}

const updateUserInfo = (arg) => {
  return request({
    method: 'post',
    url: '/account/updateUserInfo',
    data: arg,
    showLoading: false
  }).then(res => {
    return res.data
  })
}

const sendMessage = (arg)=>{
  return request({
    method: 'post',
    url: '/chat/sendMessage',
    data:arg,
    showLoading: false
  }).then(res => {
    return res.data
  })
}



export default {
  captcha,
  login,
  register,
  resetPassword,
  getContactList,
  getUser,
  uploadAvatar,
  updateUserInfo,
  sendMessage,
}









